package com.mmlc.meimei.lichengkongjian;

import android.content.Intent;
import android.graphics.Color;
import android.support.v4.view.ViewPager;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.ImageView;

import com.mmlc.inter.InterActivity;
import com.mmlc.inter.ViewPagerAdapter;
import com.mmlc.meimei.lichengkongjian.customview.GradientShaderTextView;
import com.mmlc.utils.ViewUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

public class GuideActivity extends InterActivity {

    @Override
    protected int initContentView() {
//        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        return R.layout.activity_guide;
    }

    ViewPager vp_guide;
    //    LinearLayout ll_guide_point;
    List<View> views = new ArrayList<>();
    int[] drawables = {R.drawable.guide0, R.drawable.guide1, R.drawable.guide2, R.drawable.guide3, R.drawable.guide4};
    DisplayMetrics metrics;
    GradientShaderTextView guide;
    @Override
    protected void initView() {
        vp_guide = ViewUtils.getView(activity, R.id.vp_guide);
//        ll_guide_point = ViewUtils.getView(activity, R.id.ll_guide_point);
        metrics = getResources().getDisplayMetrics();

        for (int i = 0; i < drawables.length; i++) {
            View view = getLayoutInflater().inflate(R.layout.activity_welcome, null);

            ImageView iv_content = ViewUtils.getView(view, R.id.iv_content);
            iv_content.setImageResource(drawables[i]);
            if(i == 0) {
                guide = ViewUtils.getView(view, R.id.tv_guide);
                guide.setVisibility(View.VISIBLE);
            }
            if (i == drawables.length - 1) {
//                ViewUtils.getView(view, R.id.iv_experience).setVisibility(View.VISIBLE);
                ViewUtils.getView(view, R.id.view).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        startActivity(new Intent(activity, MainActivity.class));
                        finish();
                    }
                });
            }

            views.add(view);
        }
        vp_guide.setAdapter(new ViewPagerAdapter<>(views));

//        ll_guide_point.removeAllViews();
//        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
//                18 * metrics.widthPixels / 1080,
//                18 * metrics.widthPixels / 1080);
//        for (int i = 0; i < drawables.length; i++) {
//            ImageView point = new ImageView(getApplicationContext());
//            point.setLayoutParams(params);
//            if (i == 0) params.setMargins(18 * metrics.widthPixels / 1080, 0, 0, 0);
//            if (i == 0) {
//                point.setImageResource(R.drawable.shape_circle_black);
//            } else {
//                point.setImageResource(R.drawable.shape_circle_grey);
//            }
//            ll_guide_point.addView(point);
//        }
    }

    private int clo = 1;
    public void spark() {
        Timer timer = new Timer();
        TimerTask task = new TimerTask(){
            public void run() {

                runOnUiThread(new Runnable() {
                    public void run() {
//                        if (clo == 0) {
//                            clo = 1;
//                            guide.setTextColor(Color.TRANSPARENT); // 透明
//                        } else {
                            if (clo == 1) {
                                clo = 2;
                                guide.setTextColor(Color.parseColor("#ffffff"));
                            } else if(clo == 2) {
                                clo = 1;
                                guide.setTextColor(Color.parseColor("#4a5daf"));
                            }
//                        }
                    }
                });
            }
        };
        timer.schedule(task, 3, 1000);
        // 参数分别是delay（多长时间后执行），duration（执行间隔）
    }

    @Override
    protected void initEvent() {
//        vp_guide.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
//            @Override
//            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
//
//            }
//
//            @Override
//            public void onPageSelected(int position) {
//                for (int i = 0; i < ll_guide_point.getChildCount(); i++) {
//                    ImageView point = (ImageView) ll_guide_point.getChildAt(i);
//                    if (i == position) {
//                        point.setImageResource(R.drawable.shape_circle_black);
//                    } else {
//                        point.setImageResource(R.drawable.shape_circle_grey);
//                    }
//                }
//            }
//
//            @Override
//            public void onPageScrollStateChanged(int state) {
//
//            }
//        });
    }
}
